from tkinter import *
from tkinter import ttk
import os


def ro(ad):
    def save():
        file1 = open(ad, 'w', encoding='UTF-8')
        file1.write(entry.get("1.0", "end"))
        if ad != 'com.txt':
            file2 = open('com.txt', 'w', encoding='UTF-8')
            file2.write(entry.get("1.0", "end"))

    def Open():
        os.startfile('ri.pyw')

    root2 = Tk()
    root2.geometry("550x575+550+0")
    # root2.iconbitmap('pt.ico')
    root2.title("Консоль " + ad)

    root2['background'] = '#606060'
    root2.resizable(width=False, height=False)
    file = open(ad, 'r', encoding='UTF-8')
    root2.update()
    width = root2.winfo_width()
    height = root2.winfo_height()

    entry = Text(root2)
    entry.place(width=width, height=height - 50)
    entry.insert("1.0", file.read())

    file.close()
    btn1 = ttk.Button(root2, text="Open", command=Open, width=10)
    btn = ttk.Button(root2, text="Save", command=save, width=10)

    btn.place(y=height - 37, x=width // 2 - 145)
    btn1.place(y=height - 37, x=width // 2 + 55)
    root2.mainloop()
